<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //ES5写法

        //构造函数
        function Phone(brand, price) {
            this.brand = brand
            this.price = price
        }

        //添加方法
        Phone.prototype.call = function() {
            console.log("打电话...")
        }

        //创建对象，调用方法
        let hw = new Phone('华为', 5999)
        hw.call()
        console.log(hw)

        //ES6写法
        class Phone2{
            //构造方法必须叫constructor
            constructor(brand, price) {
                this.brand = brand
                this.price = price
            }

            //定义方法使用该语法，不用用ES5的 call: function(){}
            call() {
                console.log("打电话2...")
            }
        }
        let hw2 = new Phone2('小米', 3999)
        hw2.call()
        console.log(hw2)
    </script>
</body>
</html>